import { useState, useEffect } from "react";

export function useProList(length){
    const [proList,setProList] = useState()

    useEffect(()=>{
        fetch('http://121.89.205.189:3000/api/pro/list?limitNum=' + length)
        .then(res => res.json())
        .then(res => {
            // setProList(res.data)

            // console.log(res.data);
            
            const pro = res.data.map(item => {
                return <p key={item.proid}>{item.proname}</p>
            })

            setProList(pro)
        })
      }, [])


      return proList
}


export function useTitle(title){
    useEffect(()=>{
        document.title = title
    }, [title])
}

export function useQueryId(id){
    const [dom, setDom] = useState(null)

    useEffect(()=>{
        setDom(document.getElementById(id))
    }, [id])

    return dom
}